package com.webapi.common.utils;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtils {
    
    public static final String DATE_SHORT = "yyyy-MM-dd";
    public static final String DATE_SHORT_NO = "yyyyMMdd";
    public static final String DATE_LONG = "yyyy-HH-dd HH:mm:ss";

    public static String date2stringShort(Date date) {
        return null == date ? "" : getDateFormat(DATE_SHORT).format(date);
    }

    public static String date2stringLong(Date date) {
        return null == date ? "" : getDateFormat(DATE_LONG).format(date);
    }
    
    public static Date string2dateShort(String date) {
        try {
            return getDateFormat(DATE_SHORT).parse(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }
    public static Date string2dateLong(String date) {
        try {
            return getDateFormat(DATE_LONG).parse(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }
    
    public static DateFormat getDateFormat(String s) {
        return new SimpleDateFormat(s);
    }
        
}
